With the development of complex computing applications, modern application programming has become quite intricate. Application programs created these days pose a requirement for extensive processing resources. However, available processing resources may not satisfy this requirement. Hence, it is essential that the available processing resources be optimized. At the same time, the application program needs to be run as efficiently as possible, while still maintaining the process complexities. Use of multithreaded programming has proved to be beneficial in optimizing the available processing resources as well as efficiently running the application program.
In multithreaded programming, an application program is written as a set of parallel activities or threads. A thread is an instance of a sequence of code that is executed as a unit. The partitioning of an application program into multiple threads results in easily manageable and faster program execution.
Each thread requires certain resources like processor time, memory resources, and input/output (I/O) services in order to accomplish its objective. An operating system allocates these resources to various threads. The operating system provides a scheduling service that schedules the thread for running on the processor.
In some cases, multiple threads in an application make identical calls at the same time. The exact same data is returned. Each thread runs the same exact code to parse the network response. A traditional lock makes each thread wait to take its turn, and then once a thread has it's turn it will execute the code. However, if many threads are waiting on a lock then each thread will wait to take it's turn and then execute that code. This means that the same execution takes place multiple times. This approach can be inefficient, waste bandwidth, and slow because multiple threads are fighting for the same network resources.
It would be desirable to make the thread processing more efficient so that it consumes less computing resources than a conventional approach where each thread is executed independently at or near the same time.